
export default {
  addCart(state, payload) {
    //判断商品存在否
    let goodById = state.cartList.filter(item => 
      item.goodsId === payload.goodsId
    )
    
    if (goodById.length!=0) {
      // console.log(state.cartList)
      // console.log(goodById.goodsId)
      for (let i = 0; i < state.cartList.length; i++){
        
        if (state.cartList[i].goodsId === goodById[0].goodsId) {
          state.cartList[i].num++;
          return
        }
      }
    } else {
      state.cartList.push(payload)
    }
  },
  deleteCart(state, goodsIdList) {
    for (let t = 0; t < goodsIdList.length; t++){
      let cartList = state.cartList
      //判断商品存在否
      let goodById = cartList.filter(item => 
        item.goodsId === goodsIdList[t]
      )[0]
      console.log(goodById)
      console.log(goodsIdList)
      if (goodById.length != 0) {
        //返回对应对象的index
        for (let item in cartList) {
          if (cartList[item].goodsId === goodsIdList[t])
          {
            state.cartList.splice(item, 1)
            console.log(state.cartList)
          }
          break
        }
      } 
    }
  },
  minusCart() {
    
  }
}
